﻿namespace NMA.Domain.Model
{
    using NMA.Domain.Shared;
    using NMA.Infrastructure.DBC;
    using NMA.Infrastructure.Builders;

    public class Address : IValueObject<Address>
    {
        public virtual string Street { get; private set; }
        public virtual string Ward { get; private set; }
        public virtual string District { get; private set; }

        private Address() { }

        public Address(string street, string ward, string district)
        {
            Street = street;
            Ward = ward;
            District = district;
        }

        public bool SameValueAs(Address other)
        {
            Check.Assert(other == null, "Address is null");

            return new EqualsBuilder().
                Append(Street, other.Street).
                Append(Ward, other.Ward).
                Append(District, other.District).
                IsEquals();
        }

        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return true;
            }
            if (obj == null || GetType() != obj.GetType())
            {
                return false;
            }

            Address other = (Address)obj;

            return SameValueAs(other);
        }

        public override int GetHashCode()
        {
            return new HashCodeBuilder().
                Append(Street).
                Append(Ward).
                Append(District).
                ToHashCode();
        }        
    }
}
